<?php
/*****商品管理*****/
namespace BoxAdmin\Controller;

use Think\Controller;

class BalanceController extends CommonController
{
    public function _initialize()
    {
        parent::_initialize();

    }

    public function index()
    {
        $this->type = I('type', 'payonlne');
        $this->memuNav = $this->type;
        $kw = I('get.kw', '', 'trim');
        $mintime = I('get.mintime');
        $maxtime = I('get.maxtime');
        $minmoney = I('get.minmoney');
        $maxmoney = I('get.maxmoney');
        $unset = I('get.unset');
        if ($minmoney == 0) $minmoney = '0.0';
        $where = "1";
        if (!empty($kw)) {
            $where .= " and ( remark like '%$kw%')";
        }
        if ($this->type) {
            $where .= " and type='$this->type'";
        }
        $log_type = dict('log_type');
        $this->title = $log_type[$this->type];
        if (!empty($mintime) && !empty($maxtime)) {
            $where .= ' and "' . ($mintime) . '" <= add_date && "' . ($maxtime) . ' 23:55" >=  add_date';
        }
        if (!empty($minmoney) && !empty($maxmoney)) {
            $where .= " and (num >= '$minmoney' and num <= '$maxmoney')";
        }

        //dump($where);
        $order = 'id desc';
        $data = BoxModel("SystemLog")->get($where, 10);
        foreach ($data['list'] as $k => $one) {
            $data['list'][$k]['students'] = BoxModel("edu_students")->where(array('user_id' => $one['user_id']))->find();
        }
        $this->data = $data['list'];
        $this->show_page($data['pager']);
        $this->display();
    }


    /*********提现申请****/
    public function withdraw()
    {
        $where = "1";
        $mintime = I('get.mintime');
        $maxtime = I('get.maxtime');
        if ($this->kw = I('kw')) {
            $where .= " and M.user_id = '%$this->kw%' or (remark like '%$this->kw%' or name like '%$this->kw%' or nickname like '%$this->kw%' or S.phone like '%$this->kw%' or email like '%$this->kw%')";
        }
        if (!empty($mintime) && !empty($maxtime)) {
            $where .= ' and "' . ($mintime) . '" <= addtime && "' . ($maxtime) . ' 23:55" >=  addtime';
        }
        if ($this->status = I('status')) {
            $where .= " and S.status='$this->status'";
        }
        $this->status_array = array(1 => '待处理', 2 => '已处理');
        $model = BoxModel('system_money_withdraw');
        $count = $model->alias("S")->join("system_member as M on M.user_id=S.user_id")->where($where)->count();
        $pager = $this->setPager($count, 10);
        $data = $model->alias("S")->join("system_member as M on M.user_id=S.user_id")->where($where)->field("M.*,S.*")->order("S.id desc")->limit($this->limit)->select();
        foreach($data as $k=>$one){
            $data[$k]['user']=BoxModel("system_member")->load($one['user_id']);
        }
        $this->data = $data;
        $this->display();
    }

    /******通过****/
    public function status()
    {
        $id = I('id');
        $this->data = BoxModel("system_money_withdraw")->load($id);
        $is_show = I('status');
        $r = BoxModel('system_money_withdraw')->save(array('id' => $id, 'status' => $is_show));
        $this->jump("操作成功");
    }

}

?>